# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('apr' 'apr-devel')
pkgver=1.6.3
pkgrel=1
pkgdesc="The Apache Portable Runtime"
arch=('i686' 'x86_64')
url="https://apr.apache.org/"
makedepends=('libcrypt-devel' 'libuuid-devel')
options=('!libtool')
license=('APACHE')
source=(https://archive.apache.org/dist/apr/apr-${pkgver}.tar.bz2
      'apr-1.5.0-msys2.patch'
      'binary-copy.patch'
      'no-undefined.patch'
      'tests-disable_testproc.patch'
      'tests-fix_paths.patch'
      'tests.patch'
      'fix-debian-layout.patch')
sha256sums=('131f06d16d7aabd097fa992a33eec2b6af3962f93e6d570a9bd4d85e95993172'
            'a247a6b23dd0681613297d3ecc17a3491052da5bf502181f508edc095d154503'
            '746861efed2c2e064b6acfef6ab2ee3f343ad411528a48a63dc4a3028a7aa333'
            '94657ee8603f12cc4a767f819cc52c4fef6721c98c5c94d9a5e0b8c87cdd5c72'
            'e4b823a600bc3efa948229ad12d157e8038fd570f95ca7f2f260c431eeef1a09'
            '4c90def2d0fed5abcff1752c3ba8cba5bc6a1a628904df9c7f7d6a72207f7f53'
            '969057ad2cf9253eca2eb86675d8793ac3e28a4edc3b0fb3fc54cbe3086c2a89'
            'edcb695fc87ced48cdeeb747d9b47e8cdd28ad7fcf29fa597c608fcac39621b9')

prepare() {
  cd "${srcdir}/apr-${pkgver}"

  patch -p1 -i ${srcdir}/binary-copy.patch
  patch -p1 -i ${srcdir}/no-undefined.patch
  patch -p1 -i ${srcdir}/tests-disable_testproc.patch
  patch -p1 -i ${srcdir}/tests.patch
  patch -p1 -i ${srcdir}/tests-fix_paths.patch
  patch -p1 -i ${srcdir}/apr-1.5.0-msys2.patch
  patch -p1 -i ${srcdir}/fix-debian-layout.patch

  autoreconf -fi
}

build() {
  cd "${srcdir}/apr-${pkgver}"
  ./configure --build=${CHOST} \
      --prefix=/usr \
      --libexecdir=/usr/lib/apr/modules \
      --datadir=/usr/share/apr \
      --enable-layout=Debian \
      ac_cv_header_windows_h=no \
      ac_cv_header_winsock2_h=no

  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/apr-${pkgver}"
  make -j1 check
}

package_apr() {
  depends=('libcrypt' 'libuuid')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  #cp -rf ${srcdir}/dest/usr/share/doc ${pkgdir}/usr/share/
}

package_apr-devel() {
  pkgdesc="Libapr headers and libraries"
  groups=('development')
  depends=("apr=${pkgver}" "libcrypt-devel" "libuuid-devel")
  options=('staticlibs')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share/apr ${pkgdir}/usr/share/
}
